#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <gtk/gtk.h>
#include <usb.h>
#include "modems_ids.h"

char 			*modem_type = "", *modem_iface = "";

void on_window1_destroy (GtkObject *object, gpointer user_data)
{
        gtk_main_quit();
}

void on_button3_clicked (GtkObject *object, gpointer user_data)
{
        gtk_main_quit();
}

// Поиск подключенного модема на USB и его определение
static void modem_find (void)
{
	struct usb_bus *bus;
	struct usb_device *dev;
	int modem_id;

	usb_init();
	usb_find_busses();
	usb_find_devices();

	for (bus = usb_get_busses(); bus; bus = bus->next)
	{
		// Просматриваем usb-устройства и если по vid/pid находим наше:
		for (dev = bus -> devices; dev; dev = dev -> next) {
			modem_id = (int)(dev->descriptor.idVendor << 16) |
				(int)dev->descriptor.idProduct;

			switch (modem_id) {
			case SPEEDTOUCH_330:
				//gtk_label_set_text(GTK_LABEL (label1), "SpeedTouch 330");
				modem_type = "speedtouch";
				modem_iface = "nas0";
				break;

			case ZTE_ZXDLS_852:
				//gtk_label_set_text(GTK_LABEL (label1), "ZTE ZXDSL 852");
				modem_type = "zte";
				modem_iface = "dsl0";
				break;
			} // switch (modem_id)
		} // for (dev = ...)
	} // for (bus = ...)
}

int main (int argc, char *argv[])
{
        GtkBuilder              *builder;
	GtkWidget               *window1, *window2;

        gtk_set_locale();
        gtk_init (&argc, &argv);
        
        builder = gtk_builder_new ();
        gtk_builder_add_from_file (builder, "uzadsl.glade", NULL);
 
        window1 = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
        window2 = GTK_WIDGET (gtk_builder_get_object (builder, "window2"));
        gtk_builder_connect_signals (builder, NULL);          
        g_object_unref (G_OBJECT (builder));
        
	modem_find ();

        gtk_widget_show_all (window1);
        gtk_main ();
        
        return 0;
}
